package com.example.demo;

import com.example.demo.druid.User;
import com.example.demo.druid.dao.UserMapper;
import com.example.demo.rabbitmq.SendMessage;
import com.example.demo.redis.RedisLuaUtils;
import com.example.demo.redis.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 9:12 2019/8/8
 */
@RestController
public class Controller {
   @Autowired
    private RedisUtils redisUtils;

   @Autowired
   private SendMessage sendMessage;
    public static final String LOCK_ORDER = "goods:order:lock";
   @Autowired
   private RedisLuaUtils redisLuaUtils;


    @RequestMapping("/test")
     public void aaa(){
        String mesaage="测试";
      //sendMessage.send(mesaage);
     redisLuaUtils.setLua("goods:stock:1","goods:stock:lock:1","25","0");
    }
    @RequestMapping("/unlock")
    public boolean  unlock(){
       return redisLuaUtils.unlock(LOCK_ORDER+"123","123");
    }
    @RequestMapping("/lock")
    public void   lock(){
        redisLuaUtils.setnx(LOCK_ORDER+":123","123",60000);
    }
    @Autowired
    private UserMapper userMapper;
     @RequestMapping("/user")
     public  List<User>  user(){
         List<User> users = userMapper.selectAllUser();
         return users;
     }
}
